//
//  ZYCProfileUserInfoView.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/16.
//

#import "ZYCProfileUserInfoView.h"
#import "ZYCUserInfoModel.h"

@interface ZYCProfileUserInfoView ()


@property (nonatomic, strong) UILabel *nickNameLabel;
@property (nonatomic, strong) UILabel *phoneNumberLabel;
@end
@implementation ZYCProfileUserInfoView
- (void)setModel:(ZYCUserInfoModel *)model{
    _model = model;
    NSString *role = nil;
   NSInteger roleType = [[NSUserDefaults standardUserDefaults] integerForKey:@"kUserRoleType"];
    if (roleType == 0) {
        role = @"教师";
    }else{
        role = @"家长";
    }
    if (model.realName) {
        _nickNameLabel.attributedText = [self returnStringWithString:[NSString stringWithFormat:@"%@/%@",model.realName,role]];
    }
    if (model.phonenumber) {
        NSString *phone = [NSString stringWithFormat:@"%@****%@",[model.phonenumber substringToIndex:3],[model.phonenumber substringFromIndex:model.phonenumber.length-4]];
        _phoneNumberLabel.text = phone;
    }
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.alpha = 0.8;
        self.layer.cornerRadius = 26.2f;
        self.layer.masksToBounds = YES;
        self.backgroundColor = HEX_RGB(kBgWhiteColor);
        [self addSubview:self.nickNameLabel];
        [self addSubview:self.phoneNumberLabel];
        [self.nickNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.centerY.equalTo(self.mas_centerY);
        }];
        
        [self.phoneNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(self.nickNameLabel.mas_bottom).offset(15.0f);
        }];
    }
    return self;
}

- (UILabel *)nickNameLabel {
    if (!_nickNameLabel) {
        _nickNameLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Medium", 16.0f) titleColor:HEX_RGB(kTitleDrakBlackColor) textAlignment:ZZTextAlignmentCenter];
        _nickNameLabel.attributedText = [[NSMutableAttributedString alloc] initWithString:@"加载中..."];
    }
    return _nickNameLabel;
}
- (UILabel *)phoneNumberLabel {
    if (!_phoneNumberLabel) {
        _phoneNumberLabel = [UILabel LabelWithString:@"加载中..." Font:kCustomFont(@"PingFangSC-Regular", 16.0f) titleColor:HEX_RGB(kTitleLightGrayColor) textAlignment:ZZTextAlignmentCenter];
    }
    return _phoneNumberLabel;
}

- (NSMutableAttributedString *)returnStringWithString:(NSString *)string{
    NSMutableAttributedString * attriString = [[NSMutableAttributedString alloc] initWithString:string];
    NSRange range = [string rangeOfString:@"/"];
    [attriString addAttribute:NSFontAttributeName value:kCustomFont(@"PingFangSC-Medium", 21.0f) range:NSMakeRange(0, range.location)];
    return attriString;

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
